﻿namespace Company.Core.Helpers
{
    public class CurveHelper
    {
        /// <summary>
        /// 获取当前房间保存csv的文件名
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public static string GetCurveFullName(int roomId,DateTime startTime,DateTime endTime)
        {
            //格式： 房间名id-开始日期-结束日期.csv
            string roomName = $"room{roomId}";
            string filename = $"{roomName}-{startTime.ToString("yyyyMMddHHmmss")}-{endTime.ToString("yyyyMMddHHmmss")}.csv";
            string folder = $"{Environment.CurrentDirectory}\\History\\{startTime.Year}\\";
            string fullName = $"{folder}{filename}";
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            return fullName;
        }

        /// <summary>
        /// 获取上一次曲线文件名+路径
        /// </summary>
        /// <param name="roomId"></param>
        /// <param name="startTime"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static string GetLastCurveFullName(int roomId, DateTime startTime, string?filename)
        {
            //格式： 房间名id-开始日期-结束日期.csv
            string roomName = $"room{roomId}";
            filename = $"{roomName}-{filename}.csv";
            string folder = $"{Environment.CurrentDirectory}\\History\\{startTime.Year}\\";
            string fullName = $"{folder}{filename}";
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            return fullName;
        }

        /// <summary>
        /// 获取当前房间当年的历史数据文件所在文件夹
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public static string GetCurveFolder(int year)
        {
            string folder = $"{Environment.CurrentDirectory}\\History\\{year}\\";
            return folder;
        }
    }
}
